#include "ParticleSystem.h"
#include "neiderra/core/ResourceManager.h"
#include "GLRenderer.h"
#include "Texture.h"

#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>

#include <vector>
using std::vector;

using namespace neiderra::rendering;

void glRenderer::render(PolyParticleSystem* pps)
{
/*	Particles* particles = pps->getParticles();

	int param;
	glGetIntegerv(GL_DEPTH_FUNC, &param);
	glPushAttrib(GL_CURRENT_BIT);
	glEnable(GL_TEXTURE_2D);

 	Texture *t = core->getResourceManager()->getTexture("tex_particle");
	glBindTexture(GL_TEXTURE_2D, t->name);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	
	double mat[16];
	glGetDoublev(GL_MODELVIEW_MATRIX, mat);
	vec3 u,v;

	u.x = mat[0];
	u.y = mat[4];
	u.z = mat[8];
	v.x = mat[1];
	v.y = mat[5];
	v.z = mat[9];

	glColorMask(false, false, false, false);
	glDepthMask(true);
	glDepthFunc(GL_LESS);
		
	for(Particles::iterator i = particles->begin();
		i!=particles->end(); 
		i++)
	{
		PolyParticle* pp = (PolyParticle*)*i;
		if(pp->lifetime <= 0)
			continue;

		vec3 color = pp->pos;
		vec3& vPos = pp->pos;
		color.normalize();
		vec3 sx = u*pp->size;
		vec3 sy = v*pp->size;

		vec3 ld = vPos-sx-sy;
		vec3 lu = vPos-sx+sy;
		vec3 ru = vPos+sx+sy;
		vec3 rd = vPos+sx-sy;

		glBegin(GL_TRIANGLES);
			glVertex3f(ld.x, ld.y, ld.z);
			glVertex3f(rd.x, rd.y, rd.z);
			glVertex3f(ru.x, ru.y, ru.z);
			glVertex3f(ld.x, ld.y, ld.z);
			glVertex3f(ru.x, ru.y, ru.z);
			glVertex3f(lu.x, lu.y, lu.z);
		glEnd();

	}

	glColorMask(true, true, true, true);

	glDepthFunc(GL_ALWAYS);
	glDepthMask(false);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);

	for(Particles::iterator i = particles->begin();
		i!=particles->end(); 
		i++)
	{
		PolyParticle* pp = (PolyParticle*)*i;
		if(pp->lifetime <= 0)
			continue;

		vec3 color = pp->pos;
		vec3& vPos = pp->pos;
		color.normalize();
		vec3 sx = u*pp->size;
		vec3 sy = v*pp->size;

		vec3 ld = vPos-sx-sy;
		vec3 lu = vPos-sx+sy;
		vec3 ru = vPos+sx+sy;
		vec3 rd = vPos+sx-sy;

		glBegin(GL_TRIANGLES);
		float alpha = pp->lifetime / (pps->getMaxLifetime()*0.001);
		glColor4f(0.6, 0.4, color.z, alpha);
			glTexCoord2d(0,0);
			glVertex3f(ld.x, ld.y, ld.z);
			glTexCoord2d(1,0);
			glVertex3f(rd.x, rd.y, rd.z);
			glTexCoord2d(1,1);
			glVertex3f(ru.x, ru.y, ru.z);
			glTexCoord2d(0,0);
			glVertex3f(ld.x, ld.y, ld.z);
			glTexCoord2d(1,1);
			glVertex3f(ru.x, ru.y, ru.z);
			glTexCoord2d(0,1);
			glVertex3f(lu.x, lu.y, lu.z);
		glEnd();

	}
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_BLEND);
	glDepthMask(true);

	glPopAttrib();
	glDepthFunc(param);*/
}

